package com.scetoop.bank;

import com.scetoop.banking.domain.OverdraftException;

public class Account {
    protected double balance;
    // 私有属性，账户余额(保护隐私)
//    private double balance;

    // 构造方法，初始化账户余额（先给yi点点钱）
    public Account(double init_balance) {
        this.balance = init_balance;
    }

    // 获取账户余额的方法
    public double getBalance() {
        return balance;
    }

    public boolean deposit(double amt) {
        if (amt > 0) {
            balance += amt;
            return true;
        }
        return false;
    }

    //    public boolean withdraw(double amt){
//        if (amt > 0 && amt <= balance){
//            balance -= amt;
//            return true;
//        }
//        return false;
//    }
    public void withdraw(double amt) throws OverdraftException {
        if (amt > 0) {
            if (amt <= balance) {
                balance -= amt;
            } else {
                throw new OverdraftException("资金不足", amt - balance);
            }
        }
    }
}
